import torch
from perceptron_model import Perceptron
from net_model import Net

# 加载模型
model1 = Perceptron()
model2 = Net()
model1.load_state_dict(torch.load('perceptron_model.pth'))
model2.load_state_dict(torch.load('net_model.pth'))

# 推理
print("perceptron model structure:")
# 打印提示信息，表示开始打印载入的模型结构信息
print(model1)
with torch.no_grad():
    x_test1 = torch.tensor([10.0])
    y_test1 = model1.to('cpu')(x_test1.unsqueeze(0))
    print(f'Test input: {x_test1.item()} Test output: {y_test1.squeeze().item()}')
    
# 推理
print("net model structure:")
# 打印提示信息，表示开始打印载入的模型结构信息
print(model2)
with torch.no_grad():
    x_test2 = torch.tensor([10.0])
    y_test2 = model2.to('cpu')(x_test2.unsqueeze(0))
    print(f'Test input: {x_test2.item()} Test output: {y_test2.squeeze().item()}')